package com.thlws.redis.pipeline;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.Pipeline;

/**
 * 插入大量数据使用 Pipeline
 * @author HanleyTang
 * @date 2018-12-15
 */
public class JedisPipeline {


    public static void main(String[] args) {

        try(Jedis jedis = new Jedis("localhost",6379);){

            int count = 10000;
            long start = System.currentTimeMillis();

            Pipeline pipeline = jedis.pipelined();

            for (int i=0; i<count; i++){
                //jedis.set("key"+i,"v"+i);//普通方式
                pipeline.set("keyII" + i, "vII" + i);

            }

            //管道同步
            pipeline.sync();

            long end = System.currentTimeMillis();

            System.out.println(end-start);
        }
    }
}
